package app;


import io.avaje.inject.External;
import io.jooby.RequestScope;
import jakarta.inject.Inject;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.Jdbi;

public class BaseService {
    private Jdbi jdbi;

    @Inject
    public void setJdbi(@External Jdbi jdbi) {
        this.jdbi = jdbi;
    }

    protected <T> T use(Class<T> klass) {
        Handle handle = RequestScope.get(jdbi);
        assert handle != null;
        return handle.attach(klass);
    }

}
